﻿using System;
using ePlanet.SingleWell.DataAccess;
using System.Data;

namespace ePlanet.SingleWell.Models
{
    public class AttachmentModel
    {
        private string m_DBHelperString = string.Empty;
        /// <summary>
        /// 表空间名称
        /// </summary>
        public string DBHelperString
        {
            get { return m_DBHelperString; }
            set { m_DBHelperString = value; }
        }

        private string m_AttachmentID = string.Empty;
        /// <summary>
        /// 附件ID
        /// </summary>
        public string AttachmentID
        {
            get { return m_AttachmentID; }
            set { m_AttachmentID = value; }
        }

        private string m_ObjectTableName = string.Empty;
        /// <summary>
        /// 业务数据表名
        /// </summary>
        public string ObjectTableName
        {
            get { return m_ObjectTableName; }
            set { m_ObjectTableName = value; }
        }

        private string m_AttachmentName = string.Empty;
        /// <summary>
        /// 附件文件名
        /// </summary>
        public string AttachmentName
        {
            get { return m_AttachmentName; }
            set { m_AttachmentName = value; }
        }

        private DateTime m_UpdateTime = DateTime.MinValue;
        /// <summary>
        /// 附件上传时间
        /// </summary>
        public DateTime UpdateTime
        {
            get { return m_UpdateTime; }
            set { m_UpdateTime = value; }
        }

        private long m_AttachmentSize = 0;
        /// <summary>
        /// 附件大小，单位为K
        /// </summary>
        public long AttachmentSize
        {
            get { return m_AttachmentSize; }
            set { m_AttachmentSize = value; }
        }

        private string m_DocumentType = string.Empty;
        /// <summary>
        /// 附件类型
        /// </summary>
        public string DocumentType
        {
            get { return m_DocumentType; }
            set { m_DocumentType = value; }
        }

        private byte[] m_AttachmentContent = null;
        /// <summary>
        /// 附件内容
        /// </summary>
        public byte[] AttachmentContent
        {
            get
            {
                return new AttachmentDAL(this.m_DBHelperString).GetAttachmentContentByAttachmentID(this.m_AttachmentID);
            }
            set
            {
                m_AttachmentContent = value;
            }
        }

        private Web.SystemConfig.Models.SysUser m_CreateUser = null;
        /// <summary>
        /// 上传附件者
        /// </summary>
        public Web.SystemConfig.Models.SysUser CreateUser
        {
            get
            {
                string createUserID = new AttachmentDAL(this.m_DBHelperString).GetAttachmentCreateUserIDByAttachmentID(this.m_AttachmentID);
                if (!string.IsNullOrEmpty(createUserID))
                {
                    DataTable oDataTable = new Web.SystemConfig.Business.BUSAuth_User().GetUserInfo(createUserID);
                    if (oDataTable != null && oDataTable.Rows.Count > 0)
                    {
                        this.m_CreateUser = new Web.SystemConfig.Models.SysUser();
                        m_CreateUser.RoleID = -1;
                        m_CreateUser.UserID = new Guid(createUserID);
                        m_CreateUser.UserName = oDataTable.Rows[0]["User_Name"].ToString();
                    }
                }
                return this.m_CreateUser;
            }
        }
    }
}
